<template>
  <div>
    <el-form :inline="true" :model="formInline" class="demo-form-inline">
      <el-form-item>
        <el-input v-model="formInline.deptID" placeholder="所在科室ID"></el-input>
      </el-form-item>
      <el-form-item>
        <el-input v-model="formInline.registLeID" placeholder="挂号级别ID"></el-input>
      </el-form-item>
      <el-form-item>
        <el-input v-model="formInline.userName" placeholder="用户名"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit()">查询</el-button>
        <el-button type="danger" @click="handleDelete()">批量删除</el-button>
      </el-form-item>
    </el-form>
    <!-- 表格 -->
    <el-table ref="multipleTable" :data="list" tooltip-effect="dark" style="width: 100%"
      @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="70">
      </el-table-column>
      <el-table-column label="序号" width="120">
        <template slot-scope="scope">{{  (page - 1) * limit + scope.$index + 1  }}</template>
      </el-table-column>
      <el-table-column prop="userName" label="用户名" width="190">
      </el-table-column>
      <el-table-column prop="password" label="密码" width="190">
      </el-table-column>
      <el-table-column prop="realName" label="真实姓名" width="190">
      </el-table-column>
      <el-table-column prop="isScheduling" label="参与排班" width="190">
      </el-table-column>
      <el-table-column prop="delMark" label="删除状态" width="190">
       <template slot-scope="scope">{{ scope.row.delMark==1?'正常':'已删除' }}</template>
      </el-table-column>
      <el-table-column label="操作" width="150">

        <template slot-scope="scope">
          <el-button type="warning" size="mini" @click="updateInfo(scope.row)">修改</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页器 -->
    <el-pagination
      style="margin-top: 4%"
      background
      layout="total, prev, pager, next, jumper"
      :page-size="limit"
      :current-page="page"
      :total="total"
      @current-change="getUserList"
    >
    </el-pagination>
    <!-- 修改用户信息 -->
    <el-dialog title="修改用户信息" :visible.sync="dialogFormVisible2">
      <el-form :model="updateForm">
        <el-form-item label="登录名" label-width="120px">
          <el-input v-model="updateForm.userName" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="密码" label-width="120px">
          <el-input v-model="updateForm.password" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="真实姓名" label-width="120px">
          <el-input v-model="updateForm.realName" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="用户类别" label-width="120px">
           <el-select v-model="updateForm.useType">
               <el-option
                 v-for="item in options"
                 :key="item.value"
                 :label="item.label"
                 :value="item.value">
               </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="医生职称ID" label-width="120px">
          <el-input v-model="updateForm.docTitleID" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="是否参与排班" label-width="120px">
          <el-select v-model="updateForm.isScheduling">
            <el-option label="是" value="是"></el-option>
            <el-option label="否" value="否"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="所在科室ID" label-width="120px">
          <el-input v-model="updateForm.deptID" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="挂号级别ID" label-width="120px">
          <el-input v-model="updateForm.registLeID" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible2 = false">取 消</el-button>
        <el-button type="primary" @click="updateSure">确 定</el-button>
      </div>
    </el-dialog>
  </div>

</template>

<script>
  import user from '@/api/his/user'
  export default {
    created() {
        this.getUserList()
    },
    data() {
      return {
      formInline:{
        deptID:'',
        registLeID:'',
        userName:''
      },
      // tableData:null,
      multipleSelection: [],  //选中框
      updateForm:{
      },
      dialogFormVisible2: false,
      options: [{
                    value:1,
                    label: '医院管理员'
                    }, {
                    value:2,
                    label: '挂号收费员'
                    }, {
                    value:3,
                    label: '门诊医生'
                    },{
                    value:4,
                    label: '医技医生'
                    },{
                    value:5,
                    label: '药房操作员'
                    },{
                    value:6,
                    label: '财务管理员'
                    }
                ],
       page:1,
       limit:8,
       list:null,
       total:0
      }
    },
    methods: {
      getUserList(page = 1){
        console.log("*********");
         this.page=page;
            user.getUserList(this.page,this.limit,this.formInline.deptID,this.formInline.registLeID,this.formInline.userName,this.realName,this.delMark)
            .then(res=>{
              console.log(res);
              this.list = res.data.data.list
               this.total = res.data.data.total

              console.log(this.list);
            })

      },
      onSubmit(page=1) {
        this.page=page;
        user.getUserList(this.page,this.limit,this.formInline.deptID,this.formInline.registLeID,this.formInline.userName)
        .then((res) => {
          this.list = res.data.data.list;
          this.total = res.data.data.total
          console.log(this.list)
        }).catch((err) => {
          console.log(err)
        })
      },
      handleDelete() {
        // console.log(index, row);
        user.deleteUserByIds(this.multipleSelection)
        .then(res=>{
            console.log(res);
            this.getUserList()
        })
      },
      updateSure(){
        user.updateUser(this.updateForm).then(res=>{
          console.log(res)
          if(res.data.code == 20000){
                this.$message.success('修改成功')
                this.getUserList()
                this.updateForm = {}
                this.dialogFormVisible2 = false
              }else{
                this.$message.error('修改失败')
              }
        }).catch(err=>{
          console.log(err)
        })
      },
      updateInfo(scope){
        this.dialogFormVisible2 = true
            this.updateForm = scope
            console.log(this.updateForm)
      },
      handleSelectionChange(val){
          this.multipleSelection = []
          val.forEach(item => {
             const id = item.id
             //判断数组中是否包含某个值
             if (this.multipleSelection.indexOf(id) == -1) {
                 this.multipleSelection.push(id)
             }
         })
          console.log(this.multipleSelection)
      },

    }
  }
</script>

<style scoped>
 .el-input {
    padding-left: 5px;
    max-width: 300px;
  }

  .el-select {
    padding-left: 5px;
    padding-right: 3px;
  }

  .el-pagination {
    margin-left: 30%;
  }
</style>
